package com.etpjava.action;

import java.util.ArrayList;
import java.util.List;

import com.etpjava.dao.impl.RewardDaoImpl;
import com.etpjava.model.Reward;
import com.etpjava.service.RewardService;
import com.etpjava.service.impl.RewardServiceImpl;
import com.etpjava.util.Page;
import com.opensymphony.xwork2.ActionSupport;

public class RewardAction extends ActionSupport {
	


	/**
	 * 
	 */
	private static final long serialVersionUID = 3175010800705466506L;
	private Reward reward;
	private List<Reward> rewards;
	private Integer id;
	private int[] ids;
	private Page pagelist;
	
	public static int row = 0;
	
	RewardService rewardServiceImpl = new RewardServiceImpl();
	
	
//  �������У�Ĭ����ʾ��ҳ
	public String rewardList() {
		rewards = rewardServiceImpl.findAll();
		row = 0;
		return "list";
	}
	
	public String rewardPageList() {
		if (null==pagelist) {
			pagelist=new Page(1);
		}
		pagelist.setActionname("rewardPageList");
		new RewardDaoImpl().getPagelist(pagelist);
		return "list";
	}
	
// ͨ��id����
	public String searchById() {
		if (null==pagelist) {
			pagelist=new Page(1);
		}
		System.out.print(id);
		reward = rewardServiceImpl.findById(id);
		List<Reward> list =new ArrayList<Reward>();
		list.add(reward);
		pagelist.setList(list);

//		
//		
//		pagelist.getList().add(reward);
		
		return "list";
	}
	
	
	
	
//  ��һҳ
	public String rewardListPn() {
		row = row + 15;
		rewards = rewardServiceImpl.findAll(row);
		if (rewards.size() == 0) {	//���û����һҳ	
			row = row - 15;
			rewards = rewardServiceImpl.findAll(row);
		}
		return "list";
	}
	
//  ��һҳ
	public String rewardListPp() {
		if (row == 0) {  //���û����һҳ
			rewards = rewardServiceImpl.findAll(row);
		} else {
			row = row - 15;
			rewards = rewardServiceImpl.findAll(row);
		}
		return "list";
	}
	
//βҳ
	public String rewardListEnd() {
		
			rewards = rewardServiceImpl.findAll(row);
	
			row = row - 15;
			rewards = rewardServiceImpl.findAll(row);
		
		return "list";
	}
	
//  ���һ����¼
	public String add() {
		
			rewardServiceImpl.add(reward);
		
		
		return rewardList();
	}
	
//	ɾ��һ����¼
	public String delete() {
		
		rewardServiceImpl.delete(id);
			return "list";
	}
//	ɾ����ѡ��¼
	public String deletese() {
		if (ids!=null&&ids.length!=0) {
			for (int id :ids) {
				rewardServiceImpl.delete(id);
			}
		}
		return "list";
	}
	
//��ת�����ҳ��
	public String toAdd() {
		
		return "addjsp";
	}
	
//��ת���޸�ҳ��	
	public String toUpdate() {
		
		reward = rewardServiceImpl.findById(id);
		return "updatejsp";
	}
	
	
	public String update() {
		rewardServiceImpl.modify(reward);
		return "list";
	}
	
	
	
	
	
	
	
	public Reward getReward() {
		return reward;
	}

	public void setReward(Reward reward) {
		this.reward = reward;
	}

	public List<Reward> getRewards() {
		return rewards;
	}

	public void setRewards(List<Reward> rewards) {
		this.rewards = rewards;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	public void setPagelist(Page pagelist) {
		this.pagelist = pagelist;
	}

	public Page getPagelist() {
		return pagelist;
	}
	
	public int[] getIds() {
		return ids;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}
	
}
